package com.tojabo.swing.seven_listener;

import java.awt.List;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;

public class FocusListenerDemo1 extends JFrame implements FocusListener {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	List info = new List(10);
	JTextField tf = new JTextField("");
	JButton button = new JButton("确认");

	public FocusListenerDemo1(String title) {
		super(title);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		add(info, "North");
		add(tf, "Center");
		add(button, "South");
		tf.addFocusListener(this);
	}

	public void focusGained(FocusEvent e) {
		if (e.isTemporary())// 将焦点更改事件的标识为暂时性或者永久性
			info.add("暂时性获得focus-gained-long");
		else
			info.add("长久性获得focus-gained-temp");
	}

	public void focusLost(FocusEvent e) {
		if (e.isTemporary())// 将焦点更改事件的标识为暂时性或者永久性
			info.add("暂时性失去focus-lost-long");
		else
			info.add("长久性失去focus-lost-temp");
	}

	public static void main(String[] args) {
		FocusListenerDemo1 t = new FocusListenerDemo1("测试窗口");
		t.pack();
		t.setVisible(true);
	}

}
